import request from '@/utils/request'
/**
 *获取文章列表 频道新闻推荐_V1.1
 * @param {*} id
 * @param {*} timestamp
 * @returns
 */
export const getArticleList = (id, timestamp) => {
  return request({
    method: 'get',
    url: '/v1_1/articles',
    params: {
      channel_id: id,
      timestamp,
      with_top: 1
    }
  })
}
/**
 * 对文章不喜欢(不感兴趣)
 * @param {*} id
 * @returns
 */
export function dislikeArticle(id) {
  return request({
    method: 'post',
    url: '/v1_0/article/dislikes',
    data: {
      target: id
    }

  })
}
/**
 *  举报文章
 * @param {*} id  举报id
 * @param {*} type 举报的类型
 * @returns
 */
export function reportArticle(id, type) {
  return request({
    method: 'post',
    url: '/v1_0/article/reports',
    data: {
      target: id,
      type
    }

  })
}

// 文章详情页
/**
 *   获取文章详情
 * @param {*} id
 * @returns
 */
export function getArticleDetail(id) {
  return request({
    method: 'get',
    url: '/v1_0/articles/' + id
  })
}

/**
 * 取消点赞
 * @param {*} id
 * @returns
 */
export function deleteLike(id) {
  return request({
    method: 'delete',
    url: '/v1_0/article/likings/' + id
  })
}

/**
 * 点赞
 * @param {*} id
 * @returns
 */
export function addLike(id) {
  return request({
    method: 'post',
    url: '/v1_0/article/likings',
    data: {
      target: id
    }
  })
}

/**
 *  取消不喜欢
 * @param {*} id
 * @returns
 */
export function deleteDisLike(id) {
  return request({
    method: 'delete',
    url: '/v1_0/article/dislikes/' + id
  })
}

/**
 * 喜欢
 * @param {*} id
 * @returns
 */
export function addDisLike(id) {
  return request({
    method: 'post',
    url: '/v1_0/article/dislikes',
    data: {
      target: id
    }
  })
}

/**
 * 获取评论
 * @param {*} articleId 文章id
 * @param {*} offset    上一次返回的id， 如果是第一页，可以为null
 * @returns
 */
export function getCommentList(articleId, offset) {
  return request({
    method: 'get',
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source: articleId,
      offset: offset
    }
  })
}

/**
 * 发表文章的评论
 * @param {*} articleId
 * @param {*} content
 * @returns
 */
export function addComment(articleId, content) {
  return request({
    method: 'post',
    url: '/v1_0/comments',
    data: {
      target: articleId,
      content
    }
  })
}

/**
 * 对评论点赞
 * @param {*} commentId
 * @returns
 */
export function addCommentZan(commentId) {
  return request({
    method: 'post',
    url: '/v1_0/comment/likings',
    data: {
      target: commentId
    }
  })
}

/**
 * 取消点赞
 * @param {*} commentId
 * @returns
 */
export function deleteCommentZan(commentId) {
  return request({
    method: 'DELETE',
    url: '/v1_0/comment/likings/' + commentId
  })
}

/**
 * 获取回复列表
 * @param {*} commentId
 * @param {*} offset
 * @returns
 */
export function getReplyList(commentId, offset) {
  return request({
    url: '/v1_0/comments',
    method: 'get',
    params: {
      type: 'c',
      source: commentId,
      offset
    }
  })
}

/**
 * 添加回复接口
 * @param {*} commentId
 * @param {*} content
 * @param {*} articleId
 * @returns
 */
export function addReply(commentId, content, articleId) {
  return request({
    method: 'post',
    url: '/v1_0/comments',
    data: {
      target: commentId,
      content,
      art_id: articleId
    }
  })
}
